home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 6
/
CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso
/
cucd
/
online
/
fidonetts
/
3csrc.lzh
/
3viewpkt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-03
|
6KB
|
265 lines
/*
* dummied-up type 3 ASCII packet tosser demo
* displays contents of packet ("SAMPLE.3KT" default) to screen
* Public Domain
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "3mail.h"
/* Return a line from message text -- old, old code, but it works... */
char * write_line (char **text, int linelen) {
static char line[133];
register int x = 0;
char *p;
char *pp;
if (!*text)
return "";
if (!**text)
return *text;
p = *text;
pp = line;
*pp = 0;
while (++x < (linelen + 1)) {
switch (*p) {
case '\r':
*pp = 0;
p++;
goto GotCR;
case '\0':
goto StopIt;
default:
*pp = *p;
pp++;
p++;
*pp = 0;
break;
}
}
StopIt:
if (*p == ' ') {
*pp = 0;
while (*p == ' ')
p++;
}
else if (x == (linelen + 1)) {
if (strchr (line, ' ')) {
while (p > *text && *pp != ' ') {
*pp = 0;
pp--;
p--;
}
if (p == *text) {
strncpy (line, *text, linelen + 1);
line[linelen + 1] = 0;
p += (linelen + 1);
}
else
p++;
}
}
GotCR:
while (*pp == ' ' && pp > line) { /* rstrip returned string */
*pp = 0;
--pp;
}
*text = p;
return line;
}
int import_3msg (void *dummy,PHDR3 *phdr,MHDR3 *mhdr,char *text,
int textlen,int *error) {
/* this function is called to import/forward the message
these dummy functions aren't perfect; will foul up
screen appearance when long message 'pages' buffer */
static long nummsgs = 0L;
char *p,*line,*to;
TAG3 *info;
*error = NOERR3;
printf("\n\n ** Message #%ld:\n",++nummsgs);
/* show msg hdr */
if(mhdr->from) printf("\nFrom: %s",mhdr->from);
else printf("\nNo From; damaged msg");
to = strdup(mhdr->to);
if(!to) {
if(!mhdr->area && !phdr->area) printf("\nNo To, no Area; damaged msg");
else printf("\nTo: All");
}
else {
if((p = strchr(to,'@')) != NULL) *p = 0;
printf("\nTo: %s",to);
free(to);
}
if(mhdr->date) {
printf("\nDate: %4.4s/%2.2s/%2.2s %2.2s:%2.2s:%2.2s%s",mhdr->date,
&mhdr->date[4],&mhdr->date[6],&mhdr->date[8],&mhdr->date[10],
&mhdr->date[12],&mhdr->date[14]);
}
else printf("\nNo date; damaged msg");
if(mhdr->subj) printf("\nSubj: %s",mhdr->subj);
if(phdr->area)
printf("\nArea: %s",phdr->area);
else if(mhdr->area)
printf("\nArea: %s",mhdr->area);
else printf("\n**Netmail");
if(!mhdr->id) {
printf("\nNo ID; damaged msg");
}
else {
if(*mhdr->id == ' ') {
p = strchr(mhdr->from,'@');
if(p) {
p++;
}
else p = mhdr->from;
printf("\nID: %s%s",p,mhdr->id);
}
else printf("\nID: %s",mhdr->id);
}
if(mhdr->ref) printf("\nRef: %s",mhdr->ref);
printf("\n");
info = mhdr->head;
while(info) {
printf("\n");
if(info->tag) printf("%s",info->tag);
if(info->data) {
if(info->tag) printf(" ");
printf("%s",info->data);
}
info = info->next;
}
printf("\n");
if(text && textlen) {
text[textlen] = 0; /* assure NUL termination */
p = text;
while(*p) {
line = write_line(&p,80);
fputs(line,stdout);
if(strlen(line) < 80) fputc('\n',stdout);
}
}
return 0;
}
int appendin_3msg (void *dummy,PHDR3 *phdr,MHDR3 *mhdr,char *text,
int textlen,int *error) {
/* this function is called if more than one pass at the message
* text is required
*/
char *p,*line;
*error = NOERR3;
text[textlen] = 0; /* assure NUL termination */
p = text;
while(*p) {
line = write_line(&p,80);
fputs(line,stdout);
if(strlen(line) < 80) fputc('\n',stdout);
}
return 0;
}
int check_3pkthdr (void *dummy,char *fname,PHDR3 *pkt3,int *error) {
/* this "callback" function should check packet header and decide
* if you want to process the packet. return 0 if so, anything
* else if not.
*/
TAG3 *info;
*error = NOERR3;
if(pkt3->from) printf("\n\n ** Packet \"%s\":\nFrom: %s\n",fname,pkt3->from);
else printf(" ** Packet \"%s\":\nNo From; damaged packet\n",fname);
if(pkt3->area) {
printf("Area: %s\n",pkt3->area);
}
if(pkt3->to) {
printf("To: %s\n",pkt3->to);
}
else {
if(!pkt3->area) {
printf("No To, no Area; damaged packet\n");
}
else printf("To: (Broadcast mail)\n");
}
if(pkt3->creator) printf("Creator: %s\n",pkt3->creator);
else printf("No Creator; damaged packet\n");
if(pkt3->pword) {
printf("Password: %s\n",pkt3->pword);
}
info = pkt3->head;
while(info) {
printf("\n");
if(info->tag) printf("%s",info->tag);
if(info->data) {
if(info->tag) printf(" ");
printf("%s",info->data);
}
info = info->next;
}
return 0;
}
int check_3msghdr (void *dummy,MHDR3 *msg3,int *error) {
/* this "callback" function should check message header and decide
* if you want to process the message. return 0 if so, anything
* else if not.
*/
*error = NOERR3;
return 0;
}
int main (int argc,char *argv[]) {
int error;
char *pname = "SAMPLE.3KT";
if(argc > 1) pname = argv[1];
printf("\n\n\n ** \"Processed\" %ld msgs\n",
process_3pkt(NULL,pname,&error));
if(error && error != EOP3)
error3a(error);
return error;
}